<template>
	<view class="classlist">
		<view class="left">
			<scroll-view scroll-y="true" class="scroll">
				<view class="left_ul">
					<view @click="navClick(item)" :class="category.id == item.id ? 'left_li active':'left_li'"
						v-for="(item,index) in navlist" :key="index">
						{{item.name}}
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="right">
			<view class="top">
				<image :src="category.file_path" class="topbanner" mode="widthFix"></image>
			</view>
			<view class="goods">
				<view class="goodsitem" v-for="(item,index) in goodslist" :key='index'
					@click="toPage(`/pages/goodsdetail/index?id=${item.id}`)">
					<image :src="item.cover_path" mode=""></image>
					<view class="goodsinfo">
						<view class="name">
							{{item.name}}
						</view>
						<view class="des">
							{{item.sketch}}
						</view>
						<view class="price">
							<text class="pricenum">￥{{item.price}} </text>
							<text> 已售 : {{item.sales}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCategory,
		GoodsList
	} from "@/api/api.js"
	export default {
		data() {
			return {
				navlist: [],
				goodslist: [],
				last_page: 1,
				page: 1,
				category_id: '',
				category: []
			}
		},
		onLoad() {
			this.getCategory()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.GoodsList()
			}
		},
		methods: {
			getCategory() {
				getCategory().then(res => {
					if (res.code == 0) {
						this.navlist = res.data
						this.category = this.navlist[0]
						this.GoodsList()
					}
				})
			},
			GoodsList() {
				GoodsList({
					category_id: this.category.id,
					page: this.page
				}).then(res => {
					if (res.code == 0) {
						this.goodslist = this.goodslist.concat(res.data.data)
						this.last_page = res.data.last_page
					}
				})
			},
			navClick(item, index) {
				this.category = item
				this.page = 1
				this.last_page = 1
				this.goodslist = []
				this.GoodsList()
			}
		}
	}
</script>

<style lang="scss">
	.classlist {
		display: flex;

		.left {
			width: 23%;
			height: 100vh;
			/* #ifdef H5 */
			height: calc(100vh - 44px);
			/* #endif */
			box-shadow: 1px 0 4px $uni-bg-color;
			padding-top: 40rpx;
			position: absolute;
			left: 0;
			box-sizing: border-box;

			uni-scroll-view {
				height: 100%;
			}

			.left_li {
				text-align: center;
				height: 80rpx;
				line-height: 80rpx;
				color: #4f4f4f;
				font-size: 14px;
			}

			.active {
				color: #fff;
				background: $uni-bg-color;
			}
		}

		.right {
			padding-top: 40rpx;
			position: relative;
			left: 23%;
			width: 77%;
			height: 100vh;
			/* #ifdef H5 */
			height: calc(100vh - 44px);
			/* #endif */
			overflow: scroll;
			box-sizing: border-box;

			&::-webkit-scrollbar {
				display: none;
				/* Chrome Safari */
			}

			.topbanner {
				width: 94%;
				margin-left: 3%;
				height: 8rem;
			}

			.goods {
				.goodsitem {
					display: flex;
					width: 90%;
					margin: 15px auto;

					image {
						width: 100px;
						height: 100px;
						border-radius: 5px;
					}

					.goodsinfo {
						flex: 1;
						width: calc(100% - 100px);
						margin-left: 10px;

						.name {
							margin-top: 5px;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							font-size: 14px;
						}

						.des {
							display: -webkit-box;
							-webkit-line-clamp: 2;
							-webkit-box-orient: vertical;
							overflow: hidden;
							font-size: 12px;
							height: 36px;
							line-height: 18px;
							color: #777;
							margin-top: 10px;
						}

						.price {
							margin-top: 8px;
							font-size: 12px;
							color: #777;
							display: flex;
							justify-content: space-between;
							align-items: center;

							.pricenum {
								color: #F23A3A;
								font-size: 17px;
								font-weight: bold;
							}
						}
					}
				}
			}
		}
	}
</style>